using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


using Microsoft.ConnectionEngine.Registers.Core.ServiceProvider.Common;
using Microsoft.ConnectionEngine.Registers.Core.ServiceProvider.Common.DataSets;

using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Configuration;

namespace Microsoft.ConnectionEngine.Registers.Core.ServiceProvider.DataAccess
{
    public class ServiceProviderTypeMessageType
    {

        #region Get/Search Methods
        /// <summary>
        /// Gets ServiceProviderTypeMessageType
        /// </summary>
        /// <returns>A typed dataset representing the requested ServiceProviderTypeMessageType</returns>
        [CLSCompliant(false)]
        public static dsServiceProviderTypeMessageType ServiceProviderTypeMessageTypeSearch(
            string messageTypeID, string serviceProviderTypeID)
        {
            dsServiceProviderTypeMessageType ds = new dsServiceProviderTypeMessageType();
            string SQL = "ServiceProviderTypeMessageTypeSearch";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());

            ds.ServiceProviderTypeMessageType.Load(db.ExecuteReader(SQL, messageTypeID, serviceProviderTypeID), LoadOption.OverwriteChanges);
            return ds;
        }


        /// <summary>
        /// Returns true if a ServiceProviderTypeMessageType row exists
        /// </summary>
        /// <returns>True if successful</returns>
        //public static bool ServiceProviderTypeMessageTypeExists(string messagetypeid, string sourceserviceprovidertypeid, string destinationserviceprovidertypeid)
        //{
        //    bool result = false;
        //    string SQL = "ServiceProviderTypeMessageTypeExists";

        //    Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
        //    if (Convert.ToInt32(db.ExecuteScalar(SQL, messagetypeid, sourceserviceprovidertypeid, destinationserviceprovidertypeid)) > 0)
        //        result = true;

        //    return result;
        //}

        /// <summary>
        /// Returns true if a ServiceProviderTypeMessageType row exists
        /// </summary>
        /// <param name="poolid"></param>
        /// <param name="serviceprovidertypeid"></param>
        /// <returns>True if successful</returns>
        public static bool ServiceProviderTypeMessageTypeExists(
            string messageTypeID, string sourceServiceProviderTypeID, string destinationServiceProviderTypeID)
        {
            bool result = false;
            string SQL = "ServiceProviderTypeMessageTypeExists";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            if (Convert.ToInt32(db.ExecuteScalar(
                SQL, messageTypeID, sourceServiceProviderTypeID, destinationServiceProviderTypeID)) > 0)
                result = true;

            return result;
        }

        #endregion

        #region Insert Methods

        /// <summary>
        /// Inserts a new ServiceProviderTypeMessageType
        /// </summary>
        /// <returns>A new ID if successful, otherwise empty string</returns>
        public static bool ServiceProviderTypeMessageTypeInsert(
            string messageTypeID, string sourceServiceProviderTypeID, string destinationServiceProviderTypeID)
        {
            bool result = true;
            string SQL = "ServiceProviderTypeMessageTypeInsert";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            if (db.ExecuteNonQuery(SQL, messageTypeID, sourceServiceProviderTypeID, destinationServiceProviderTypeID) <= 0)
                result = false;

            return result;
        }

        #endregion

        #region Delete Methods

        /// <summary>
        /// Deletes a ServiceProviderTypeMessageType
        /// </summary>
        /// <returns>True if successful</returns>
        public static bool ServiceProviderTypeMessageTypeDelete(string serviceProviderTypeMessageTypeID)
        {
            bool result = true;
            string SQL = "ServiceProviderTypeMessageTypeDelete";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            if (db.ExecuteNonQuery(SQL, serviceProviderTypeMessageTypeID) <= 0)
                result = false;

            return result;
        }


        /// <summary>
        /// Deletes all ServiceProviderTypeMessageType records belonging of a specific MessageType
        /// </summary>
        /// <returns>True if successful</returns>
        public static bool ServiceProviderTypeMessageTypeDeleteByMessageTypeID(string messageTypeID)
        {
            bool result = true;
            string SQL = "ServiceProviderTypeMessageTypeDeleteByMessageTypeID";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            //if there are no links then nothing will be deleted
            db.ExecuteNonQuery(SQL, messageTypeID);   

            return result;
        }


        /// <summary>
        /// Deletes all ServiceProviderTypeMessageType records belonging to a specific ServiceProviderType
        /// </summary>
        /// <param name="serviceprovidertypeid"></param>
        /// <returns>True if successful</returns>
        public static bool ServiceProviderTypeMessageTypeDeleteByServiceProviderTypeID(string serviceProviderTypeID)
        {
            bool result = true;
            string SQL = "ServiceProviderTypeMessageTypeDeleteByServiceProviderTypeID";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            db.ExecuteNonQuery(SQL, serviceProviderTypeID); 

            return result;
        }

        #endregion

    }
}
